<template>
  <view class="task-page">
    <!-- 积分信息 -->
    <view class="points-header">
      <text class="points-number">{{ userPoints }}</text>
      <text class="points-label">账户积分</text>
    </view>

    <!-- 签到区域 -->
    <view class="checkin-section">
      <view class="checkin-header">
        <text class="checkin-title">已连续签到{{ checkinDays }}天</text>
        <view class="checkin-btn" @tap="dailyCheckin">
          <text class="checkin-text">点击签到</text>
        </view>
      </view>
      
      <!-- 签到日历 -->
      <view class="checkin-calendar">
        <view 
          v-for="(day, index) in checkinCalendar" 
          :key="index"
          class="calendar-day"
          :class="{ 'checked': day.checked, 'today': day.isToday }"
        >
          <view class="day-icon">⭐</view>
          <text class="day-points">{{ day.points }}</text>
        </view>
      </view>
    </view>

    <!-- 任务列表 -->
    <view class="tasks-section">
      <view class="section-title">任务列表</view>
      
      <view class="tasks-list">
        <view 
          v-for="(task, index) in tasksList" 
          :key="index"
          class="task-card"
        >
          <view class="task-info">
            <text class="task-title">{{ task.title }}</text>
            <text class="task-desc">{{ task.description }}</text>
          </view>
          
          <view class="task-action">
            <view 
              class="task-btn"
              :class="{ 'completed': task.completed }"
              @tap="completeTask(task)"
            >
              <text class="btn-text">{{ task.completed ? '已完成' : '去完成' }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

const userPoints = ref(0)
const checkinDays = ref(0)

const checkinCalendar = ref([
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: true, isToday: false },
  { points: 1, checked: false, isToday: true }
])

const tasksList = ref([
  {
    id: 1,
    title: '发起一键回收订单',
    description: '每日0/0次 每次+0积分',
    completed: false,
    points: 10
  },
  {
    id: 2,
    title: '阅读文章',
    description: '每日0/0次 每次+0积分',
    completed: false,
    points: 5
  }
])

const dailyCheckin = () => {
  const today = checkinCalendar.value.find(day => day.isToday)
  
  if (today && !today.checked) {
    today.checked = true
    checkinDays.value += 1
    userPoints.value += today.points
    
    uni.showToast({
      title: `签到成功！获得${today.points}积分`,
      icon: 'success'
    })
  } else {
    uni.showToast({
      title: '今日已签到',
      icon: 'none'
    })
  }
}

const completeTask = (task) => {
  if (task.completed) {
    uni.showToast({
      title: '任务已完成',
      icon: 'none'
    })
    return
  }
  
  // 模拟完成任务
  task.completed = true
  userPoints.value += task.points
  
  uni.showToast({
    title: `任务完成！获得${task.points}积分`,
    icon: 'success'
  })
}
</script>

<style lang="scss" scoped>
.task-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding: 24rpx 32rpx;
}

.points-header {
  text-align: center;
  padding: 40rpx 0;
}

.points-number {
  font-size: 72rpx;
  font-weight: bold;
  color: #8BC34A;
  display: block;
  line-height: 1;
}

.points-label {
  font-size: 24rpx;
  color: #666;
  margin-top: 8rpx;
}

.checkin-section {
  background: white;
  border-radius: 20rpx;
  padding: 32rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}

.checkin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32rpx;
}

.checkin-title {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.checkin-btn {
  background: linear-gradient(135deg, #8BC34A 0%, #7CB342 100%);
  color: white;
  padding: 16rpx 32rpx;
  border-radius: 50rpx;
  box-shadow: 0 4rpx 12rpx rgba(139, 195, 74, 0.3);
  transition: all 0.3s ease;
}

.checkin-btn:active {
  transform: scale(0.95);
}

.checkin-text {
  font-size: 24rpx;
  font-weight: 600;
}

.checkin-calendar {
  display: flex;
  justify-content: space-between;
  gap: 16rpx;
}

.calendar-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20rpx 0;
  background: #f8f8f8;
  border-radius: 16rpx;
  transition: all 0.3s ease;
}

.calendar-day.checked {
  background: rgba(139, 195, 74, 0.1);
  border: 2rpx solid rgba(139, 195, 74, 0.3);
}

.calendar-day.today {
  background: linear-gradient(135deg, rgba(139, 195, 74, 0.2) 0%, rgba(139, 195, 74, 0.1) 100%);
  border: 2rpx solid #8BC34A;
}

.day-icon {
  font-size: 32rpx;
  margin-bottom: 8rpx;
  color: #8BC34A;
}

.day-points {
  font-size: 20rpx;
  color: #666;
}

.tasks-section {
  background: white;
  border-radius: 20rpx;
  padding: 32rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}

.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 24rpx;
}

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

.task-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 0;
  border-bottom: 2rpx solid #f0f0f0;
}

.task-card:last-child {
  border-bottom: none;
}

.task-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.task-title {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
  margin-bottom: 8rpx;
}

.task-desc {
  font-size: 24rpx;
  color: #999;
}

.task-action {
  margin-left: 24rpx;
}

.task-btn {
  padding: 16rpx 32rpx;
  border-radius: 50rpx;
  background: linear-gradient(135deg, #8BC34A 0%, #7CB342 100%);
  color: white;
  transition: all 0.3s ease;
}

.task-btn:active {
  transform: scale(0.95);
}

.task-btn.completed {
  background: #ccc;
}

.btn-text {
  font-size: 24rpx;
  font-weight: 500;
}
</style>